package org.pengge.rxjava.web.api.first.impl;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import org.pengge.rxjava.web.api.first.ChapterTwoApi;
import org.springframework.stereotype.Service;


/**
 * @author
 * @since 2017/7/26 下午4:35
 * Purpose
 */
@Service
public class ChapterTwoApiimpl implements ChapterTwoApi {
    @Override
    public Observable<String> queryBaidu() {


        return Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            //当有订阅者的时候，回调subscribe方法
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                System.out.println("开始执行异步，获取百度信息");
                Thread.sleep(5000);
                e.onNext("获取数据成功");
                e.onComplete();
                System.out.println("异步线程执行结束");
            }
        });
    }
}
